package com.hyh.toyshopping.controller;

import com.hyh.toyshopping.commons.Result;
import com.hyh.toyshopping.model.Comment;
import com.hyh.toyshopping.model.Toy;
import com.hyh.toyshopping.model.view.CommentView;
import com.hyh.toyshopping.service.ToyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.toyshopping.controller
 * @Author:hyhWTX
 * @ClassName:ToyController
 * @CreateTime:2022年-12月-14日 20:18
 * @Description: TODO (一句话描述以下该类的功能)
 */
@RestController
@RequestMapping("/toys")
public class ToyController {

    @Autowired
    private ToyService toyService;
    @GetMapping("/getToys")
    public List<Toy> getToys(int toy_is_display){
        return toyService.getToys(toy_is_display);
    }
    @GetMapping("/getToyDesc")
    public Toy getToyDesc(int toy_id){
        return toyService.getToyById(toy_id);
    }
    @RequestMapping("/comment/getToyComment")
    public List<CommentView> getToyComment(int toy_id){
        return  toyService.getToyComment(toy_id);
    }

    @RequestMapping("/comment/addComment")
    public Result addComment(@RequestBody Comment comment){
        toyService.addToyComment(comment);
        return  Result.success("评论成功！");
    }
    @PutMapping("/updateToyDisplayStatus")
    public Result updateToyDisplayStatus(int toy_id,int toy_is_display){
        toyService.updateToyDisplayStatus(toy_id,toy_is_display);
        return toy_is_display==0?Result.success("上架成功"):Result.success("下架成功");
    }
}
